﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting;

namespace MiniKsiegowosc.RaportTools
{
    public partial class FormMonthRaportPrint : FormRaportPrintSetup
    {
        private MonthReportBase  _Report;
        private FormMonthRaportPrint()
        {
            InitializeComponent();
        }
        public FormMonthRaportPrint(int rok, MonthReportBase report)
        {
            InitializeComponent();
            _Report = report;
            _Report.Rok = rok;
        }

        public DialogResult ShowPrintDialog()
        {
            DialogResult dlg = this.ShowDialog();
            if (dlg == System.Windows.Forms.DialogResult.OK)
            {
                XtraReport r = new XtraReport();
                r.Pages.Clear();
                MonthReportBase m = null;
                foreach (int month in monthCheckedListBox1.GetCheckedMonths())
                {
                    m = _Report.GetClonedReport();
                    if (m != null)
                    {
                        m.Miesiac = month;
                        m.Rok = _Report.Rok;
                        m.GetData();
                        m.CreateDocument();
                        r.Pages.AddRange(m.Pages);
                    }
                }

                switch (PrintType)
                {
                    case ReportPrintType.ExportToPDF:
                        r.ExportToPdf(PdfFile);
                        break;
                    case ReportPrintType.Preview:
                        r.ShowPreviewDialog();
                        break;
                    default:
                        r.Print(Printer);
                        break;
                }
                r.Dispose();
            }
            return dlg;
        }

        public static DialogResult ShowPrintDialog(int rok, MonthReportBase report)
        {
            FormMonthRaportPrint p = new FormMonthRaportPrint(rok, report);
            DialogResult dlg = p.ShowPrintDialog();
            p.Dispose();
            return dlg;
        }

        private void btnMarkAll_Click(object sender, EventArgs e)
        {
            markAll(true);
        }
        private void markAll(bool mark)
        {
            for (int i=1; i < 13; i++)
                monthCheckedListBox1.MarkMonth(i, mark);
        }
        private void btnUnMarkAll_Click(object sender, EventArgs e)
        {
            markAll(false);
        }
    }
}
